import java.util.Vector;
import java.util.Random;

/*
	TODO:
	* Party Healing Support
	* Better Containers
*/
public class Party
{
	// note that I have two vectors here, when I really should have some kind of
	// multidimensional array.
	 private Vector<Combatant> vCombatants;
	 private Vector<Combatant> vAvailableCombatants;
	 private Random rGenerator;
	 private String sName;
	 private Encounter eEncounter;
	 public Party()
	 {
	 	 vCombatants  = new Vector<Combatant>();
	 	 vAvailableCombatants = new Vector<Combatant>();
	 	 rGenerator  = new Random();
	 	 sName = "Unnamed Party";
	 }
	 public String getName()
	 {
	 	 return sName;
	 }
	 public Encounter getEncounter()
	 {
	 	 return eEncounter;
	 }
	 public void setName(String sNewName)
	 {
	 	 sName = sNewName;
	 }
	 public boolean isAlive()
	 {
	 	 if(unitsLeft() > 0)
	 	 {
	 	 	 return true;
	 	 }
	 	 return false;
	 }
	 public int unitsLeft()
	 {
	 	 return vAvailableCombatants.size();
	 }
	 public Combatant getRUnit()
	 {
	 	 int iMembers = vAvailableCombatants.size();
	 	 if (iMembers == 0)
	 	 {
	 	 	 return null;
	 	 }
	 	 return getUnit(rGenerator.nextInt(iMembers));
	 }
	 public Combatant getROUnit(Combatant cNotMe)
	 {
	 	 if (vAvailableCombatants.size() == 0)
	 	 {
	 	 	 return null;
	 	 }
	 	 int iAvoid = vAvailableCombatants.indexOf(cNotMe); // -1 if not found
	 	 if(iAvoid != -1)
	 	 {
	 	 	 if (unitsLeft() == 1)
	 	 	 {
	 	 	 	 return null; // there's nobody left but me
	 	 	 }
			 else
			 {
				 int iIndex = iAvoid;
				 while(iIndex == iAvoid)
				 {
					 iIndex = rGenerator.nextInt(vAvailableCombatants.size());
				 }
				 return getUnit(iIndex);
			 }
		 }
		 else
		 {
			 return getUnit(rGenerator.nextInt(vAvailableCombatants.size()));
		 }
	 }
	 public Combatant getUnit(int i)
	 {
	 	 return vAvailableCombatants.elementAt(i);
	 }
	 public void addUnit(Combatant NewGuy)
	 {
	 	 vCombatants.add(NewGuy);
	 	 vAvailableCombatants.add(NewGuy);
	 	 NewGuy.setParty(this);
	 	 //System.out.println(NewGuy.getName());
	 }
	 public void delUnit(Combatant Leaving)
	 {
	 	 vAvailableCombatants.remove(Leaving);
	 }
	 public void setEncounter(Encounter eNewEncounter)
	 {
	 	 eEncounter = eNewEncounter;
	 }
}
